<?php
/*
  @Author: Hong Ta
  @Copyright: ABC Company
 */

mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');


Yii::app()->params->profile = ProfileChild::model()->findByPk(1); // use the admin's profile since the user hasn't logged in
$jsVersion = '?' . Yii::app()->params->buildDate;

// blueprint CSS framework
$themeURL = Yii::app()->theme->getBaseUrl();
// Added by Hong Ta
Yii::app()->clientScript->registerCssFile($themeURL . '/css/bootstrap.min.css', 'screen,projection');
Yii::app()->clientScript->registerCssFile($themeURL . '/css/bootstrap-responsive.min.css', 'screen,projection');
Yii::app()->clientScript->registerCssFile($themeURL . '/css/font-awesome.min.css', 'screen,projection');
Yii::app()->clientScript->registerCssFile($themeURL . '/css/ace.min.css', 'screen,projection');
Yii::app()->clientScript->registerCssFile($themeURL . '/css/ace-responsive.min.css', 'screen,projection');
Yii::app()->clientScript->registerCssFile($themeURL . '/css/ace-skins.min.css', 'screen,projection');
// Default css
// Yii::app()->clientScript->registerCssFile($themeURL.'/css/screen.css'.$jsVersion,'screen, projection');
// Yii::app()->clientScript->registerCssFile($themeURL.'/css/print.css'.$jsVersion,'print');
// Yii::app()->clientScript->registerCssFile($themeURL.'/css/main.css'.$jsVersion,'screen, projection');
// Yii::app()->clientScript->registerCssFile($themeURL.'/css/form.css'.$jsVersion,'screen, projection');
// Yii::app()->clientScript->registerCssFile($themeURL.'/css/ui-elements.css'.$jsVersion,'screen, projection');


$backgroundImg = '';
$defaultOpacity = 1;
$themeCss = '';

$checkResult = false;
$checkFiles = array(
    'themes/x2engine/images/x2footer.png' => '1393e4af54ababdcf76fac7f075b555b',
    'themes/x2engine/images/x2-mini-icon.png' => '153d66b514bf9fb0d82a7521a3c64f36',
);
foreach ($checkFiles as $key => $value) {
    if (!file_exists($key) || hash_file('md5', $key) != $value)
        $checkResult = true;
}
$theme2Css = '';
if ($checkResult)
    $theme2Css = '#bg{display:none !important;}';

// check for background image, use it if one is set
if (empty(Yii::app()->params->profile->backgroundImg))
    $backgroundImg = CHtml::image(Yii::app()->getBaseUrl() . '/uploads/defaultBg.jpg', '', array('id' => 'bg'));
else
    $backgroundImg = CHtml::image(Yii::app()->getBaseUrl() . '/uploads/' . Yii::app()->params->profile->backgroundImg, '', array('id' => 'bg'));

if (!empty(Yii::app()->params->profile->backgroundColor)) {
    $themeCss .= 'body {background-color:#' . Yii::app()->params->profile->backgroundColor . ";}\n";

    if (!empty($backgroundImg)) {
        $shadowRgb = 'rgb(0,0,0,0.5)'; // use a black shadow if there is an image
    } else {
        $shadowColor = X2Color::hex2rgb(Yii::app()->params->profile->backgroundColor); // if there is no BG image, calculate a darker tone for the shadow

        foreach ($shadowColor as &$value) {
            $value = floor(0.5 * $value);
        }
        $shadowRgb = 'rgb(' . implode(',', $shadowColor) . ')';
    }
    $themeCss .= "#page {
-moz-box-shadow: 0 0 30px $shadowRgb;
-webkit-box-shadow: 0 0 30px $shadowRgb;
box-shadow: 0 0 30px $shadowRgb;
}\n";
}
if (!empty(Yii::app()->params->profile->menuBgColor))
    $themeCss .= '#main-menu-bar {background:#' . Yii::app()->params->profile->menuBgColor . ";}\n";

if (!empty(Yii::app()->params->profile->menuTextColor))
    $themeCss .= '#main-menu-bar ul a, #main-menu-bar ul span {color:#' . Yii::app()->params->profile->menuTextColor . ";}\n";


Yii::app()->clientScript->registerCss('applyTheme', $themeCss, 'screen', CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCss('applyTheme2', $theme2Css, 'screen', CClientScript::POS_HEAD);
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo Yii::app()->language; ?>" lang="<?php echo Yii::app()->language; ?>">
    <head>
        <meta charset="UTF-8" />
        <meta name="language" content="<?php echo Yii::app()->language; ?>" />

        <meta name="description" content="CRM Engine - Customer Relationship Management (CRM) and Sales Force Application">
            <meta name="keywords" content="CRM,customer relationship management,contact management,sales force,php">

                <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />
                <!-- <link rel="icon" href="<?php echo Yii::app()->getBaseUrl(); ?>/images/favicon.ico" type="image/x-icon0" /> -->
                <!-- <link rel="shortcut-icon" href="<?php echo Yii::app()->getBaseUrl(); ?>/images/favicon.ico" type="image/x-icon" /> -->
                <!--[if lt IE 8]>
                <link rel="stylesheet" type="text/css" href="<?php echo $themeURL; ?>/css/ie.css" media="screen, projection" />
                <![endif]-->
                <title><?php echo CHtml::encode($this->pageTitle); ?></title>
                </head>
                <body class="login-layout">
                    <div class="main-container container-fluid">
                        <div class="main-content">
                            <div class="row-fluid">
                                <div class="span12">
                                	<div class="login-container">
                                		<div class="row-fluid">
			                                <div class="center">
			                                    <h1>
			                                        <i class="icon-leaf green"></i>
			                                        <span class="red">CRM</span>
			                                        <span class="white">Engine</span>
			                                    </h1>
			                                    <h4 class="blue">&copy; Company Name</h4>
			                                </div>
			                            </div>
			                            <div class="space-6"></div>
                                    	<?php echo $content; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Custom css -->
                    <!--basic scripts-->

                    <!--[if !IE]>-->

                    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

                    <!--<![endif]-->

                    <!--[if IE]>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <![endif]-->

                    <!--[if !IE]>-->

                    <script type="text/javascript">
                        window.jQuery || document.write("<script src='<?php echo $themeURL; ?>/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
                    </script>

                    <!--<![endif]-->

                    <!--[if IE]>
    <script type="text/javascript">
     window.jQuery || document.write("<script src='assets/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
    </script>
    <![endif]-->

                    <script type="text/javascript">
                        if("ontouchend" in document) document.write("<script src='<?php echo $themeURL; ?>/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
                    </script>
                    <script src="<?php echo $themeURL; ?>/js/bootstrap.min.js"></script>

                    <!--page specific plugin scripts-->

                    <!--ace scripts-->

                    <script src="<?php echo $themeURL; ?>/js/ace-elements.min.js"></script>
                    <script src="<?php echo $themeURL; ?>/js/ace.min.js"></script>

                    <!--inline scripts related to this page-->

                    <script type="text/javascript">
                        function show_box(id) {
                            $('.widget-box.visible').removeClass('visible');
                            $('#'+id).addClass('visible');
                        }
                    </script>
                </body>
                </html>
